#!/bin/bash
scriptWorkd=$(cd "$(dirname $0)";pwd)

### ========= 全局变量 ===========
### ==============================

### ========= 前置文件 ===========
if [[ -f ${HOME}/bin/basic_func.sh ]];then  ### 存在才载入
    source ${HOME}/bin/basic_func.sh
elif [[ -f ${scriptWorkd}/../bin/basic_func.sh ]];then
    source ${scriptWorkd}/../bin/basic_func.sh
elif [[ -f ./bin/basic_func.sh ]];then
    source ./bin/basic_func.sh
fi
### ==============================


function main() {
set -e
    ## 开始信息
    echo -e "${blue4}\n$(basename $0)\n${normal}"
    echo -e "${hintStrProcessing}为root添加.vimrc"

    if [[ $(whoami) == root ]];then
        echo "运行脚本不要用sudo，之后脚本会自己申请sudo权限"
        exit
    fi
    dir=${HOME};
    sudo sh -c 'echo -e " " >/root/.vimrc'
    sudo sh -c "sed -i '1c\map! jj <Esc>' /root/.vimrc"
    echo -e "${hintStrOK}完成，vimrc如下"
    sudo cat /root/.vimrc
    if [[ ! -f ${dir}/.vimrc ]];then
        sudo cp /root/.vimrc ${dir}/.vimrc
    fi

    ## 结束信息
    echo -e "${green4}\n$(basename $0)\n${normal}"
}
main $@
